/*
 * @Descripttion: 
 * @Mender: zhtao
 * @Date: 2020-05-21 18:45:53
 * @LastEditors: zhtao
 * @LastEditTime: 2020-06-04 10:58:08
 */
import * as API_Address from '../../api/address'
import * as API_Members from '../../api/members'
import * as API_Distribution from '../../api/distribution'
import * as API_Trade from '../../api/trade'
import {
  Foundation,
  RegExp
} from '../../ui-utils/index'
import QRCode from '../../utils/weapp-qrcode.js'
let util = require('../../utils/util.js')
const App = getApp()

Page({
  data: {
    finished: false,
    from: '', // 页面涞源
    vipInfo: [],
    shop_id: null
  },
  //确定删除
  confirmDel: util.throttle(function () {
    let that = this
    API_Address.deleteAddress(that.data.addr_id).then(() => {
      that.setData({
        isdelAddress: true
      })
      wx.showToast({
        title: '删除成功'
      })
      that.getAddressList()
    })
  }),
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) { // 设置页面来源
    this.setData({
      from: options.from || ''
    })
    console.log(options.vip_id)
    API_Members.getVipShop({
      lat:12,
      lon:12,
      sort:1
    }).then((response) => {
      let vipInfo = response.filter(item => {
        return item.member_vip_do.vip_grade_id == options.vip_id;
      });
      console.log(vipInfo)
      let shop_id = vipInfo[0].member_vip_do.shop_id
      this.setData({
        vipInfo: vipInfo[0],
        shop_id: shop_id
      })
      API_Distribution.generateRShortLink().then(response => {
        let su = response.message.split('?su=')[1]
        new QRCode('myQrcode', {
          text: `https://h5.oupinguoji.cn/shop/shopDetail?su=${su}&shop_id=${shop_id}`,
          width: 110,
          height: 110,
          correctLevel: QRCode.CorrectLevel.L, // 二维码可辨识度
          callback: (res) => {
            console.log(res)
          }
        })
      })
    })
  },
  onShow() { // 获取地址列

  },
  vipBenefit() {
	console.log('会员权益')  
	wx.navigateTo({
	  url: '/pages/vipBenefitDemo/vipBenefitDemo?id=' + this.data.shop_id
	})
  },
  goShop() {
    wx.navigateTo({
      url: '/pages/shop/shop_id/shop_id?id=' + this.data.shop_id
    })
  },
  goMyFunds() {
    wx.navigateTo({
      url: "/ucenter/my-funds/my-funds?shop_id=" + this.data.shop_id
    })
  },
  goMyTeam() {
    wx.navigateTo({
      url: "/ucenter/my-team/my-team?shop_id=" + this.data.shop_id
    })
  }
})